$(function(){
	//时间插件
	laydate({
		elem: '#selectFromDate', //目标元素。
		format: 'YYYY-MM-DD'
	});
	laydate({
		elem: '#selectToDate', //目标元素。
		format: 'YYYY-MM-DD'
	});
	
});


$("#searchBtn").click(function (){
	getIssue();
});

//根据时间和用户名查询
function getIssue(){
	var fromDate = $("#selectFromDate").val();
	var toDate = $("#selectToDate").val();
	var sStatus = $('input:radio[name="status"]:checked').val();
	var parm = {fromDate:fromDate,toDate:toDate,sStatus:sStatus};
	$.getJSON('shopListByTime',parm, function(data){
		$("#table").bootstrapTable('load', data);
	});
}



$(":radio").click(function(){
	$("#table").bootstrapTable('refresh');
});

function queryParams(p){
	var status = $('input:radio[name="status"]:checked').val();
	p.status = status;
	p.standDown = 0;
	return p;
}

/*
 * 格式化操作列
 */
function state(value, row, index) {
	var image_url = row.image_url;
	var image = image_url.substr(0, 25);
	if(image_url != null){
		image;
		return [
//			"<img src=" + "http://192.168.3.37:8088/adicms_image" + image + " style='width:150px;height:150px;' class='img-rounded'/>"
			"<img src=" + "http://47.104.67.69:8088/adicms_image" + image + " style='width:150px;height:150px;' class='img-rounded'/>"
//			"<img src=" + "http://127.0.0.1:8088/adicms_image" + image + " style='width:150px;height:150px;' class='img-rounded'/>"
		].join('');	
	}
}

function operating_status(value, row, index) {

    var ident_status = row.ident_status;
    if(ident_status == 1){
        return [
            "<a class='detail' href='javascript:void(0)'>查看详情</a> | <a class='scandetail' href='javascript:void(0)'>查看鉴定信息</a>"
        ].join('');
    }
    if(ident_status == 0){
        return [
            "<a class='detail' href='javascript:void(0)'>查看详情</a> | <a class='' href='javascript:void(0)' style='color: #A60000'>未鉴定</a>"
        ].join('');
    }
	// return [
	// 	"<a class='detail' href='javascript:void(0)'>查看详情</a> | <a class='scandetail' href='javascript:void(0)'>查看鉴定信息</a>"
	// ].join('');
}


function showDeatil(shopId){
		
	$.post("shopInfoByShopId",{
	shopId : shopId,
	},function(data){
		
		$("#shopId").text(data[0].shop_id);
		$("#shopTypeName").text(data[0].shop_type_name);
		$("#shopName").text(data[0].shop_name);
		$("#shopPrice").text(data[0].shop_price);
		$("#shopCount").text(data[0].shop_count);
		$("#standard").text(data[0].standard);
		$("#author").text(data[0].author);
		$("#years").text(data[0].years);
		$("#addTime").text(data[0].add_time);
		if(data[0].s_status == 0){
			$("#sStatus").text("出售");
			$("#shopZltime").text(data[0].shop_zltime);
		}else if(data[0].s_status == 1){
			$("#sStatus").text("租赁");
		}else{
			$("#sStatus").text("竞拍");
			/*$("#zjtime").text("开始时间-结束时间");
			$("#shopZltime").text(data[0].aution_start_time+"  ----  "+data[0].aution_stop_time);*/
		}
		$("#icdn").text(data[0].icdn);
		$("#shopDescribe").text(data[0].shop_describe);

		str = data[0].image_url; //这是一字符串 
		var strs= new Array(); //定义一数组 
		strs=str.split(";"); //字符分割 
		for (i=0;i<strs.length-1 ;i++ ) 
		{ 
//			$("#imageUrl").attr("src","http://127.0.0.1:8088/adicms_image" + strs[i]);
//			document.write(strs[i]+"<br/>"); //分割后的字符输出 
//			console.log(strs[i]+"<br/>");
//			$("#imageUrl").append("<img src=" + "http://127.0.0.1:8088/adicms_image" + strs[i] + " style='width:157px;height:150px;float: left;margin-left: 2px;' class='img-rounded'/>");
			$("#imageUrl").append("<img src=" + "http://47.104.67.69:8088/adicms_image" + strs[i] + " style='width:157px;height:150px;float: left;margin-left: 2px;' class='img-rounded'/>");					
					
		} 
		
//		$("#qrcodeUrl").attr("src","http://127.0.0.1:8088/adicms_image" + data[0].qrcode_url); 
		$("#qrcodeUrl").attr("src","http://47.104.67.69:8088/adicms_image" + data[0].qrcode_url); 
	},"json");
}



function showscanDeatil(shopId){
	
	var data = null;
	
	$.post("shopIdentScanById", {
		shopId : shopId,
	}, function(data) {
		$("#i_shopId").text(data[0].shop_id);
		$("#i_shopName").text(data[0].shop_name);
		for(var i=0;i< data.length;i++){
		/*	$("#cc").append("<tr><th data-align='center' style='width: 100px; height: 40px;'>文件路径</th><td data-align='center' onclick='id_url(this)' colspan='3' style='width: 100px; height: 40px;'>"+data[i].iden_url+"</td><th>扫描日期</th><td data-align='center' colspan='2' style='width: 100px; height: 40px;'>"+data[i].scan_time+"</td><td><button type='button' onclick='show()' class='btn btn-default' style='width: 150px;'>点击复制文件路径</button></td></tr>");
		*/
			$("#cc").append("<tr><th data-align='center' style='width: 100px; height: 40px;'>文件路径</th><td data-align='center' onclick='id_url(this)' oncopy='execCopy(event,this)' colspan='3' style='width: 100px; height: 40px;'>"+data[i].iden_url+"</td><th>扫描日期</th><td data-align='center' colspan='2' style='width: 100px; height: 40px;'>"+data[i].scan_time+"</td></tr>");
		}
	}, "json");
}

function id_url(td){
	 var url = td.innerHTML;
	 document.execCommand("copy"); // 执行浏览器复制命令
	 layer.msg("文件路径复制成功", {icon : 1,time : 3000,});
}

// 实现复制 
function execCopy(event,thisDiv){
    if(isIE()){
        if(window.clipboardData){
            window.clipboardData.setData("Text", thisDiv.textContent);
//            alert(window.clipboardData.getData("Text"));
        }
    }else{
        event.preventDefault();
        if (event.clipboardData) {
            event.clipboardData.setData("text/plain", thisDiv.textContent);
//            alert(event.clipboardData.getData("text"));
        }
    }
}

function isIE(){
    var input = window.document.createElement ("input");
    //"!window.ActiveXObject" is evaluated to true in IE11
    if (window.ActiveXObject === undefined) return null;
    if (!window.XMLHttpRequest) return 6;
    if (!window.document.querySelector) return 7;
    if (!window.document.addEventListener) return 8;
    if (!window.atob) return 9;
    //"!window.document.body.dataset" is faster but the body is null when the DOM is not
    //ready. Anyway, an input tag needs to be created to check if IE is being
    //emulated
    if (!input.dataset) return 10;
    return 11;
}

/**
 * 操作列的事件监听
 */
window.operateEvents = {
	'click .detail': function(e, value, row, index) {
		var shopId = row.shop_id;
		showDeatil(shopId);
		$('#modal-detail').modal('toggle');
	},
	'click .scandetail': function(e, value, row, index) {
		var shopId = row.shop_id;
		showscanDeatil(shopId);
		$('#modal-scandetail').modal('toggle');
	}
};
